package com.gitee.dupe.authority.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gitee.dolt.boot.service.SuperServiceImpl;
import com.gitee.dupe.authority.dao.UserRoleMapper;
import com.gitee.dupe.authority.entity.UserRole;
import com.gitee.dupe.authority.service.IUserRoleService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author LYH
 * @since 2020-09-03
 */
@Service
public class UserRoleServiceImpl extends SuperServiceImpl<UserRoleMapper, UserRole> implements IUserRoleService {

    @Override
    public boolean removeByUserId(Long userId) {
        return remove(Wrappers.<UserRole>lambdaQuery().eq(UserRole::getUserId, userId));
    }

    @Override
    public List<UserRole> findAllByUserId(Long userId) {
        return list(Wrappers.<UserRole>lambdaQuery().eq(UserRole::getUserId, userId));
    }

    @Override
    public boolean removeByUserIdAndRoleIds(Long userId, List<Long> roleIds) {
        if (roleIds.isEmpty()) {
            return true;
        }
        return remove(Wrappers.<UserRole>lambdaQuery().eq(UserRole::getUserId, userId).in(UserRole::getRoleId, roleIds));
    }
}
